package com.djmw.mouse.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import com.djmw.mouse.service.constants.Constants;

//JPA标识
@Entity
@Table(name = "t_company")
public class Company extends IdEntity {
    public static final int ENABLE = 0;
    public static final int DISABLE = 1;

    private String name;
    private int status;
    private double balance;
    private String briefName;
    private int type;
    private int size;
    private Industry industry;
    private Industry industry2;
    private int province;
    private int city;
    private String address;
    private String zipcode;
    private String homepage;
    private String homepage2;
    private String contactor;
    private String cellphone;
    private String phone;
    private String fax;
    private String email;
    private String introduction;
    private Set<Bookmark> bookmark = new HashSet<Bookmark>(0);
    private Avatar avatar;

    public Company() {
        super();
    }
    public Company(Long id) {
        super(id);
    }

    @NotBlank
    @Column(name = "c_name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @Range(min = 0, max = 1)
    @Column(name = "c_status")
    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }

    @Column(name = "c_balance")
    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    }

    @Column(name = "c_brief_name")
    public String getBriefName() {
        return briefName;
    }
    public void setBriefName(String briefName) {
        this.briefName = briefName;
    }

    @Column(name = "c_type")
    public int getType() {
        return type;
    }
    public void setType(int type) {
        this.type = type;
    }
    @Transient
    public String getTypeName() {
        return type == 0 ? "" : Constants.COMPANY_TYPES.get(type).getName();
    }

    @Column(name = "c_size")
    public int getSize() {
        return size;
    }
    public void setSize(int size) {
        this.size = size;
    }
    @Transient
    public String getSizeName() {
        return size == 0 ? "" : Constants.COMPANY_SIZES.get(size).getName();
    }

    // @NotBlank
    @ManyToOne
    @JoinColumn(name = "c_industry")
    public Industry getIndustry() {
        return industry;
    }
    public void setIndustry(Industry industry) {
        this.industry = industry;
    }

    @ManyToOne
    @JoinColumn(name = "c_industry_2")
    public Industry getIndustry2() {
        return industry2;
    }
    public void setIndustry2(Industry industry) {
        this.industry2 = industry;
    }

    @Column(name = "c_province")
    public int getProvince() {
        return province;
    }
    public void setProvince(int province) {
        this.province = province;
    }
    @Transient
    public String getProvinceName() {
        return province == 0 ? "" : Constants.PROVINCES.get(province).getName();
    }

    @Column(name = "c_city")
    public int getCity() {
        return city;
    }
    public void setCity(int city) {
        this.city = city;
    }
    @Transient
    public String getCityName() {
        return city == 0 ? "" : Constants.CITIES.get(city).getName();
    }

    // @NotBlank
    @Column(name = "c_address")
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }

    // @NotBlank
    @Column(name = "c_zipcode")
    public String getZipcode() {
        return zipcode;
    }
    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    @Column(name = "c_homepage")
    public String getHomepage() {
        return homepage;
    }
    public void setHomepage(String homepage) {
        this.homepage = homepage;
    }

    @Column(name = "c_homepage_2")
    public String getHomepage2() {
        return homepage2;
    }
    public void setHomepage2(String homepage) {
        this.homepage2 = homepage;
    }

    @Column(name = "c_contactor")
    public String getContactor() {
        return contactor;
    }
    public void setContactor(String contactor) {
        this.contactor = contactor;
    }

    @Column(name = "c_cellphone")
    public String getCellphone() {
        return cellphone;
    }
    public void setCellphone(String cellphone) {
        this.cellphone = cellphone;
    }

    @Column(name = "c_phone")
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Column(name = "c_fax")
    public String getFax() {
        return fax;
    }
    public void setFax(String fax) {
        this.fax = fax;
    }

    @Column(name = "c_email")
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "c_introduction")
    public String getIntroduction() {
        return introduction;
    }
    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.company", cascade = CascadeType.ALL)
    public Set<Bookmark> getBookmark() {
        return bookmark;
    }
    public void setBookmark(Set<Bookmark> bookmark) {
        this.bookmark = bookmark;
    }

    @Transient
    public Avatar getAvatar() {
        if (avatar == null) {
            avatar = AvatarHelper.getCompanyAvatarHelper().getAvatar(id);
        }
        return avatar;
    }
}
